package utils
{
	import com.greensock.TweenLite;
	import com.greensock.TweenMax;
	import com.greensock.TweenNano;
	import com.greensock.easing.Back;
	import com.greensock.easing.Cubic;
	
	import flash.display.DisplayObject;
	
	import interfaces.ILayoutAnimationFrame;
	
	import mvc.views.frames.Frame;

	public class UtilsAnimation
	{
		/**
		 * 面板动画1
		 * @param _startFrame
		 * @param _endFrame
		 */
		public static function showLayoutAnimation1(_startFrame:Frame,_endFrame:Frame,_onComplete:Function):void
		{
			var _start:ILayoutAnimationFrame = _startFrame as ILayoutAnimationFrame;
			var _end:ILayoutAnimationFrame = _endFrame as ILayoutAnimationFrame;
			_start.startAnimation();
			TweenMax.to(_start.holderPanel.content,0.1,{alpha:0,onComplete:function():void{
				TweenMax.to(_startFrame, 0.2, {colorTransform:{tint:0xffffff, tintAmount:2, exposure:2, brightness:0}, ease:Back.easeIn,onComplete:function():void{
					TweenMax.to(_startFrame, 0.6, {scaleX:0.7,scaleY:0.7,x:_end.positionX, y:_end.positionY, motionBlur:true,  ease:Cubic.easeOut,onComplete:function():void{
						_endFrame.width = _startFrame.width;
						_endFrame.height = _startFrame.height;
						_endFrame.visible=true;
						//渐变之前的面板
						TweenNano.to(_startFrame,0.2,{alpha:0});
						//设置新面板的状态
						TweenMax.to(_endFrame,0,{alpha:0,colorTransform:{tint:0xffffff, tintAmount:2, exposure:2, brightness:0}});
						//用scale来恢复原样比直接设置长宽稳定,不然有可能会严重变形
						TweenMax.to(_endFrame,0.3,{scaleX:1,scaleY:1,onComplete:function():void{
							_onComplete.call();
							//渐变新面板到正常状态
							TweenMax.to(_endFrame,0.3,{alpha:1,colorTransform:{tint:0xffffff, tintAmount:0, exposure:0, brightness:0}});
						}});
					}});
				}});				
			}});
		}
		
		/**
		 * 显示面板样式1
		 * @param _target
		 */
		public static function showFrameStyle1(_target:DisplayObject,_fromAlpha:int=0):void
		{
			_target.alpha = _fromAlpha;
			
			TweenMax.to(_target,0.5,{alpha:1,colorTransform:{tint:0xffffff, tintAmount:2, exposure:2, brightness:0}, ease:Back.easeIn,onComplete:function():void{
				TweenMax.to(_target,0.5,{colorTransform:{tint:0xffffff, tintAmount:0, exposure:0, brightness:0},ease:Back.easeOut});
			}});
		}
	}
}